/**
 * Created by tanbingqin on 2020/9/3.
 */
import { messages } from "share/common";
import React from 'react';
import { connect } from 'react-redux';
import {
  Button, Popover, message, Col, Row, Dropdown
} from 'antd';
import formService from 'containers/setting/form/form.service';
import errorMessage from 'share/errorMessage';
import 'styles/setting/form/form-list.scss';
import FormList from 'containers/setting/form/form-list-v2';
import MetadataList from 'containers/setting/form/metadata-list'
import Condition from 'components/condition';
const If = Condition.If;
import emptyImg from 'images/travel/empty.png';

class FormListV3 extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      selectedItem: {}, //选中的左侧的菜单项
    }
  }

  //处理选中左侧的菜单项
  handleSelect = (selectedItem) => {
    this.setState({loading: true}, () => {
      this.setState({selectedItem, loading: false});
    });
  };

  render() {
    const { loading, selectedItem } = this.state;
    return (
      <div className="form-list">
        <div className="left-block">
          <MetadataList onSelect={this.handleSelect} />
        </div>
        <div className="right-block">
          <If value={selectedItem && selectedItem.categoryType === 'form' && !loading}>
            <FormList selectedItem={selectedItem}/>
          </If>
          <If value={!selectedItem.id || selectedItem.categoryType !== 'form'}>
            <div style={{marginTop: 100, textAlign: 'center'}}>
              <img src={emptyImg} style={{marginBottom: 18, width: 68, height: 68}} />
              <p style={{color: '#4E5B71'}}>{messages('common.empty.text')/*暂无数据*/}</p>
            </div>
          </If>
        </div>
      </div>
    )
  }
}

FormListV3.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps(state) {
  return {
    company: state.login.company
  }
}

export default connect(mapStateToProps)(FormListV3);